package com.fable.sp.core.domain;

import org.springframework.util.StringUtils;

import java.io.Serializable;

/**
 * .
 *
 * @author stormning on 16/7/30.
 */
public class Background implements Serializable {

    private String color;

    private String url;

    private Position position;

    public Position getPosition() {
        return position;
    }

    public void setPosition(Position position) {
        this.position = position;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    @Override
    public String toString() {
        if (url != null || color != null) {
            StringBuilder style = new StringBuilder();
            style.append("background:");
            String color = getColor();
            if (StringUtils.hasText(color)) {
                style.append(" ").append(color);
            }
            String url = getUrl();
            if (StringUtils.hasText(url)) {
                style.append(" url('").append(url).append("')");
            }
            Position position = getPosition();
            if (position != null) {
                Integer top = position.getTop();
                if (top != null) {
                    style.append(" top ").append(top);
                }
                Integer right = position.getRight();
                if (right != null) {
                    style.append(" right ").append(right);
                }
                Integer bottom = position.getBottom();
                if (bottom != null) {
                    style.append(" bottom ").append(bottom);
                }
                Integer left = position.getLeft();
                if (left != null) {
                    style.append(" left ").append(left);
                }
            }
            style.append(";");
            return style.toString();
        }
        return "";
    }
}
